package com.heihei.controller.son;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heihei.common.page.Query;
import com.heihei.common.response.ResponseVO;
import com.heihei.entity.son.SonSongEntity;
import com.heihei.service.son.SonSongService;
import com.heihei.vo.son.SongWithSingerNameVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 歌曲表 前端控制器
 * </p>
 *
 * @author duanhengfei
 * @since 2021-11-29
 */
@Api(tags = "歌曲 Controller")
@RestController
@RequestMapping("/son/song")
public class SonSongController {
    @Resource
    private SonSongService sonSongService;

    //按道理说，是有多个歌手合唱一首歌的情况的，这样的话，song跟singer应该是多对多的关系
    //现在暂时不考虑这个，之后再改吧，目前就当做是singer和song一对多的关系，暂时写接口出来，以供前端测试

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public ResponseVO<String> add(@RequestBody SonSongEntity paramEntity) {
        return this.sonSongService.myAdd(paramEntity);
    }

    @ApiOperation(value = "修改")
    @PatchMapping("/update")
    public ResponseVO<Boolean> update(@RequestBody SonSongEntity paramEntity) {
        return this.sonSongService.myUpdateById(paramEntity);
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true, paramType = "path", dataType = "String")
    @DeleteMapping("/delete/{id}")
    public ResponseVO<Boolean> delete(@PathVariable String id) {
        return this.sonSongService.deleteByIdLogic(id);
    }

    @ApiOperation(value = "批量删除（直接传入一个id数组）")
    @DeleteMapping("/delete-batch")
    public ResponseVO<Boolean> deleteBatch(@RequestBody List<String> idList) {
        return this.sonSongService.deleteBatch(idList);
    }

    @ApiOperation(value = "列表查询（分页、条件查询）")
    @GetMapping("/pageList")
    public ResponseVO<IPage<SongWithSingerNameVO>> list(SongWithSingerNameVO entityParam, Query query) {
        return this.sonSongService.myPageList(entityParam, query);
    }

    @ApiOperation(value = "详情")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true, paramType = "path")
    @GetMapping("/detail/{id}")
    public ResponseVO<SongWithSingerNameVO> detail(@PathVariable String id) {
        return this.sonSongService.myGetById(id);
    }

}
